function bw = fillArea(bw)
% FILLAREA fills the area enclosed by the object boundaries in the binary
%   image BW.
% 
% Project:  Foreground detection [Bildfolgen LU]@CVL/TUWIEN
% Author:   Gruppe 10
% Date:     03/2011
T_ME = 20; % threshold
pf = 0; pl = 0;     % previous first/last
[row xx] = find(bw);
for r = min(row):max(row)
    [xx f] = find(bw(r,:), 1, 'first'); 
    [xx l] = find(bw(r,:), 1, 'last');
    if (r~=min(row))
        if(isempty(f))% || abs(f-pf)>T_ME)    % no pixel in row
            f = pf;
        end
        if(isempty(l)) % || abs(l-pl)>T_ME)     % no pixel in row
            l = pl;
        end
    end
    bw(r, max(1,f):min(l,end)) = 1;
    pf = f; pl = l;
end
end